home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1491 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Q: realloc->free?
  5. Date: Sun, 14 Jan 1996 16:53:48 GMT
  6. Organization: Netcom
  7. Message-ID: <30f93438.164984896@nntp.ix.netcom.com>
  8. References: <4daa2e$oh5@axe.netdoor.com>
  9. NNTP-Posting-Host: ix-dc18-06.ix.netcom.com
  10. X-NETCOM-Date: Sun Jan 14  8:53:09 AM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. esargent@netdoor.com (Eric Sargent) wrote:
  14.  
  15. |>    This is probably a dumb question, but I can't find any
  16. specific or
  17. |>exact information about this.  Given this:
  18. |>
  19. |>char *a, *b;
  20. |>
  21. |>a = malloc(10);
  22. |>...
  23. |>/*
  24. |>    later we need to increase the size
  25. |>*/
  26. |>...
  27. |>b = realloc(a, 100);
  28. |>
  29. |>    Now let's say realloc had to move the data so a != b.  Does
  30. realloc
  31. |>free the memory previously pointed to by a or should it be
  32. explicitly
  33. |>freed if realloc returns a new location?  I checked the FAQ, but
  34. there
  35. |>was nothing specific about realloc.  Thanks for any information.
  36.  
  37. realloc() will free() the pointer if it has to allocate memory in a
  38. different location.  You must not free the old pointer in this case
  39. and, in fact, according to the standard you cannot even meaningfully
  40. compare the returned pointer to the old one since the old one may
  41. refer to freed space.
  42.  
  43.  
  44. Michael M Rubenstein
  45.